﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data;
using PWS.Entities;

namespace PWS.DAL
{
    public class OrderAccess
    {
        private static Order OrderFields(DataRow Row)
        {
            Order o = new Order();
            o.OrderId = (int)Row["fldOrderId"];
            o.OrderQuantity = (int)Row["fldOrderQuantity"];
            o.OrderTotal = (decimal)Row["fldOrderTotal"];
            return o;
        }
        private static Order[] DataSetToOrderArray(DataSet ds3)
        {
            Order[] orders = new Order[ds3.Tables[0].Rows.Count];
            for (int i = 0; i < ds3.Tables[0].Rows.Count; ++i)
            {
                orders[i] = OrderFields(ds3.Tables[0].Rows[i]);
            }
            return orders;
        }
        public static Order[] GetOrders()
        {
            DataSet ds3 = SqlHelper.ExecuteDataset(ConfigurationManager.ConnectionStrings["PineDB"].ConnectionString, "Orders_Get_Orders");
            return DataSetToOrderArray(ds3);
        }

    }
}
